package com.jcfk.system.controller;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import com.jcfk.system.domain.po.SysPortalContent;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

import com.jcfk.system.domain.query.SysPortalContentQuery;
import com.jcfk.system.domain.dto.SysPortalContentDTO;
import com.jcfk.system.service.SysPortalContentService;

/**
 * 门户内容
 *
 * @author awei
 * @email 522891237@gqq.com
 * @date 2024-03-25
 */
@Api(tags = {"门户内容管理"})
@RestController
@RequestMapping("sysPortalContent")
public class SysPortalContentController {
    @Autowired
    private SysPortalContentService sysPortalContentService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<SysPortalContentQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询门户内容")
    @PostMapping("/queryByPage")
    public RetPage<SysPortalContentDTO> queryByPage(@RequestBody ReqPageParam<SysPortalContentQuery> requestParam) {
        DataPage<SysPortalContentDTO> page = new DataPage<SysPortalContentDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
                SysPortalContentDTO.class);
        page = sysPortalContentService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     *  门户内容
     * 根据id 查询详情
     */
    @ApiOperation("查询门户内容")
    @GetMapping("/get/{id}")
    public RetResult<SysPortalContentDTO> get(@PathVariable("id") String id) {
            SysPortalContentDTO item = sysPortalContentService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理门户内容
     */
    @ApiOperation("保存门户内容")
    @PostMapping("/save")
    @RequestLogHeader(modular = "门户内容管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid SysPortalContentDTO sysPortalContent) {


        if (StrUtil.isEmpty(sysPortalContent.getId())){
            // 新增
            sysPortalContentService.insert(sysPortalContent);
        } else{
            // 更新
            sysPortalContentService.update(sysPortalContent);
        }
        return RetResult.ok();

    }

    /**
     *  批量删除门户内容
     */
    @ApiOperation("批量删除门户内容")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "门户内容管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody SysPortalContentDTO sysPortalContent) {
        return RetResult.ok(sysPortalContentService.logicDeleteList(sysPortalContent));
    }

    /**
     *  是否已被禁用（0 - 禁用， 1 - 启用）
     */
    @ApiOperation("上下架")
    @PostMapping("/enabled")
    public RetResult<?> enabled(@RequestBody SysPortalContent sysPortalContent){
        sysPortalContentService.enabled(sysPortalContent);
        return RetResult.ok();
    }



}
